
#include <a_master>

static const wgradient[] =
{
	8,
	16,
	15,
	13,
	12,
	14,
	7,
	10,
	0
};

new Float:epicentre[2];


forward UpdateMeteo();
forward SetFireStorm();

public OnFilterScriptInit()
{
	SetTimer("UpdateMeteo", 6 * 1000, true);
	SetFireStorm();
	SetTimer("SetFireStorm", 4 * 60000, true);
	return 1;
}


public UpdateMeteo()
{
	new Float:x, Float:y, Float:z;
	new Float:dist, Float:c[2];
	//new weatherid;
	c[0] = epicentre[0]*epicentre[0] + epicentre[1]*epicentre[1];
	for(new i=0; i<MAX_PLAYERS; i++) if(GetPlayerPos(i, x, y, z))
	{
		c[1] = x*x + y*y;
		dist = c[0] + c[1] - 2 * (epicentre[0]*x + epicentre[1]*y);
		//floatsqroot(floatpower(epicentre[0]-x, 2) + floatpower(epicentre[1]-y, 2) + floatpower(epicentre[2]-z, 2));
		new weathid = floatround(dist / (500 * 500));
		weathid = (weathid >= sizeof(wgradient)) ? wgradient[sizeof(wgradient)-1] : wgradient[weathid];
		SetPlayerWeather(i, weathid);
	}
	return true;
}

public SetFireStorm()
{
	new msg[64];
	for(new i = 0; i<2; i++) epicentre[i] = float(random(6000)-3000);
	format(msg, sizeof(msg), "Meteo station: Storm at x:%0.2f y:%0.2f", epicentre[0], epicentre[1]);
	SendClientMessageToAll(0xFFFFFFFF, msg);
	return true;
}








